package com.example.classes;

import java.security.MessageDigest;
import java.math.BigInteger;
import java.security.NoSuchAlgorithmException;

 /**
 * Encryptor class utilizing MD5
 * @author Andrew Essig
 * @version 1.0
 */
public class Encryptor
{
    public Encryptor() {}

     /**
     * Encryption method; digests a string and returns the hash as a string.
     * @param str String to be digested
     * @return String of digest message
     */
    public static String encrypt(String str){
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.reset();
            md.update(str.getBytes());
            byte[] dat = md.digest();
            BigInteger i = new BigInteger(1,dat);
            String hashtext = i.toString(16);
            while(hashtext.length() < 32 )
            {
                hashtext = "0"+hashtext;
            }
            return hashtext;
        } catch(NoSuchAlgorithmException e)
        {
            return null;
        }
    }
}